﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

using Microsoft.Win32;

namespace DanielVaughan.Calcium.VSIntegration
{
	class RegistryUtil
	{
		public static string GetCalciumInstallDirectory(CalciumProduct version, string vsVersion, string calciumVersion)
		{
			bool is64Bit = Environment.Is64BitOperatingSystem;
			string registreyKey;
			string keyStart = @"SOFTWARE\" + (is64Bit ? @"Wow6432Node\" : string.Empty);

			if (version == CalciumProduct.Phone)
			{
				registreyKey = keyStart + @"Daniel Vaughan\Calcium SDK for Windows Phone\" + calciumVersion + @"\Setup";
			}
			else
			{
				registreyKey = keyStart + @"Daniel Vaughan\Calcium SDK VS" + vsVersion + @"\" + calciumVersion + @"\Setup";
			}
			//MessageBox.Show(registreyKey);
			RegistryKey regKey = null;
			try
			{
				regKey = Registry.LocalMachine.OpenSubKey(registreyKey);

				string result = regKey.GetValue("InstallDir").ToString();
				return result;
			}
			finally
			{
				if (regKey != null)
				{
					regKey.Close();
				}
			}
		}
	}
}
